home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13157 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  55 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Philippe Verdy <100105.3120@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: ODBC SQL problems
  5. Date: 23 Mar 1996 21:25:16 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4j1q7s$q4r@arl-news-svc-3.compuserve.com>
  8. NNTP-Posting-Host: dd50-130.compuserve.com
  9.  
  10. matthew@iapps.com (Matthew Baird) s'Θcrit :
  11. > I've written an application that allows the user to pass SQL queries to an 
  12. > ODBC datasource, then dynamically binds the columns and displays the results 
  13. > in a template. I have two problems currently:
  14. >     How do I truncate the data in a SQL_TIMESTAMP field so that when I
  15. > display it, the field shows only the date portion? Here is a snippet of code:
  16. > case SQL_TIMESTAMP:
  17. > data[i] = new UCHAR[24];
  18. > rc = SQLBindCol(hstmt, i+1, SQL_C_CHAR, data[i], 24, &outlen[i]);
  19. > break;
  20. > Interestingly it doesn't matter how much space I allocate in my new UCHAR 
  21. > line, but if I change the 24 in the SQLBindCol, I get strange errors.
  22.  
  23. Don't bind SQL_C_CHAR variables, but bind a more appropriate
  24. type which allows date/time manipulation. Depending on your
  25. development system, you should find a type like the DBDATETIME
  26. structure on which operations are possible like extracting the
  27. date and time numeric values. Binding strings is not portable
  28. because it is RDBMS dependant. Another solution is to select
  29. a SQL-provided conversion to a string.
  30.  
  31. >     
  32. >     My second question is if a user enters a query that is made of two 
  33. > distinct queries ie.
  34. >     Delete from table where user='smith' Select * from table
  35. > how do I fetch only the results from the valid SELECT statement?
  36. >
  37.  
  38. Use a loop which reads each result set separately. This is not
  39. portable to some RDBMS (Oracle supports only one result set,
  40. Sybase and Microsoft SQL-Server do however).
  41. Second solution: don't use ODBC, but use more performant API's
  42. like the DB-Library for Sybase or Microsoft SQL-Server.
  43.  
  44. > Thanks,
  45. > Matthew@iapps.com
  46.  
  47.